package com.example.sys.async.handler.impl;

import cn.hutool.http.HttpUtil;
import com.example.core.constant.Constant;
import com.example.core.utils.StringUtils;
import com.example.sys.async.po.SysASync;

/***
 * 国都短信处理类
 */
public class GuoDuSmsHandlerImpl extends AbstractASyncHandlerImpl {

    private String url;
    private String appId;
    private String appPasswd;

    public String getUrl() {
        if (StringUtils.isNotEmpty(this.url)) {
            this.url = getEnvironment().getProperty("sms.guodu.url");
        }
        return url;
    }

    public String getAppId() {
        if (StringUtils.isNotEmpty(this.appId)) {
            this.appId = getEnvironment().getProperty("sms.guodu.appId");
        }
        return this.appId;
    }

    public String getAppPasswd() {
        if (StringUtils.isNotEmpty(this.appPasswd)) {
            this.appPasswd = getEnvironment().getProperty("sms.guodu.appPasswd");
        }
        return appPasswd;
    }

    /***
     * 发送短信
     * @param sysASync
     * @return
     */
    @Override
    public SysASync handler(SysASync sysASync) {
        String para = "OperID=" + getAppId() + "&OperPass=" + getAppPasswd() + "&DesMobile=" + sysASync.getTarget() + "&Content=" + sysASync.getContext();
        String result = HttpUtil.post(getUrl(), para);
        if (StringUtils.isNotEmpty(result)){
            sysASync.setExtraParameter(result.split(Constant.COMMA)[1]);
        }
        sysASync.setSuccessed(true);
        return sysASync;
    }
}
